import 'dart:math' as math;

import 'package:flutter/material.dart';

class SixPointedStarPainter extends CustomPainter {
  final Color color;

  SixPointedStarPainter({this.color = Colors.black});

  @override
  void paint(Canvas canvas, Size size) {
    final paint = Paint()
      ..color = color
      ..style = PaintingStyle.fill;

    final center = Offset(size.width / 2, size.height / 2);
    final outerRadius = size.width / 2;
    final innerRadius = outerRadius / 2;

    final Path path = Path();

    // 绘制第一个等边三角形
    for (int i = 0; i < 3; i++) {
      final angle = (i * 120 - 90) * 3.14159 / 180;
      final x = center.dx + outerRadius * cos(angle);
      final y = center.dy + outerRadius * sin(angle);

      if (i == 0) {
        path.moveTo(x, y);
      } else {
        path.lineTo(x, y);
      }
    }
    path.close();

    // 绘制第二个倒置的等边三角形
    final Path invertedTriangle = Path();
    for (int i = 0; i < 3; i++) {
      final angle = (i * 120 + 90) * 3.14159 / 180;
      final x = center.dx + outerRadius * cos(angle);
      final y = center.dy + outerRadius * sin(angle);

      if (i == 0) {
        invertedTriangle.moveTo(x, y);
      } else {
        invertedTriangle.lineTo(x, y);
      }
    }
    invertedTriangle.close();

    // 合并两个三角形形成六芒星
    canvas.drawPath(path, paint);
    canvas.drawPath(invertedTriangle, paint);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) => false;

  double cos(double angle) => math.cos(angle);
  double sin(double angle) => math.sin(angle);
}

// 使用示例
class StarWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return CustomPaint(
      size: Size(100, 100),
      painter: SixPointedStarPainter(color: Colors.blue),

    );
  }
}
